package pl.edu.agh.logview.webservice;
import java.net.URL;
import java.util.Calendar;
import java.util.GregorianCalendar;

import javax.xml.namespace.QName;
import javax.xml.ws.Service;
import javax.xml.ws.soap.SOAPBinding;


/*
 * Przykład klasy klienckiej korzystającej z Web Service'u. 
 */
public final class Client {

    private static final String PROTOCOL = "http://";
	private static final String WSDL_PATH = "logServerReceiver?wsdl";
	private static final String SERVICE_CLASS_NAME = "LogServerReceiver";
	private static final String NAMESPACE = "http://logserver.ps.sem7.agh/";
	private static final String PORT = "9000";
	private static final String HOST = "localhost";
    
    
	private static final QName SERVICE_NAME = new QName(NAMESPACE, SERVICE_CLASS_NAME);
    private static final QName PORT_NAME    = new QName(NAMESPACE, SERVICE_CLASS_NAME + "Port");


    private Client() {
    } 

    public static void main(String args[]) throws Exception {

        // Konfiguracja Endpointów
    	String endpointAddress = PROTOCOL + HOST + ":" + PORT + "/" + WSDL_PATH;
    	Service service = Service.create(new URL(endpointAddress),SERVICE_NAME);
        service.addPort(PORT_NAME, SOAPBinding.SOAP11HTTP_BINDING, endpointAddress);        
        LogServerReceiver lsr = service.getPort(LogServerReceiver.class);
        
        
        //Teraz pozostaje tylko wysłanie odpowiedniej wiadomości
        Calendar cal = new GregorianCalendar(2012,Calendar.NOVEMBER,15);
        MessageBean messageBean = new MessageBeanImpl("STAN","GOTOWY",cal.getTime(), null, null);        
        System.out.println(lsr.pushMessage(messageBean));

        cal.add(Calendar.MONTH, 2);
        messageBean = new MessageBeanImpl("WIADOMOSC","Wykonalem czynnosc A",cal.getTime(), "ZBYSZEK", "WACEK");        
        System.out.println(lsr.pushMessage(messageBean));

        cal.add(Calendar.YEAR, 1);
        messageBean = new MessageBeanImpl("WIADOMOSC","Wiadomosc B",cal.getTime(), "ALA", "OLA");        
        System.out.println(lsr.pushMessage(messageBean));



    }

}
